package com.classicInterview;

/**
 * @Author: huangzhigao
 * @Date: 2023/5/7 17:11
 */
public class Code169 {
    public int majorityElement(int[] nums) {
        int target = 0;
        int count = 0;
        for (int i = 0; i < nums.length; i++) {
            if (count == 0) {
                target = nums[i];
                count++;
            } else if (target == nums[i]) {
                count++;
            } else {
                count--;
            }
        }
        return target;
    }
}
